﻿Module ModARInvoice

    Sub Main()

        Dim sFuncName As String = String.Empty
        Dim sErrDesc As String = String.Empty
        Dim oARInvoice As AE_EASIPOS_INTEGRATION_DLL.clsARInvoice = New AE_EASIPOS_INTEGRATION_DLL.clsARInvoice

        Dim oDataSetInvoice As DataSet = Nothing

        Try

            sFuncName = "Create_ARInvoice()"
            Console.WriteLine("Starting Function", sFuncName)
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Starting function", sFuncName)

            'Getting the Parameter Values from App Cofig File
            Console.WriteLine("Calling GetSystemIntializeInfo() ", sFuncName)
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Calling GetSystemIntializeInfo()", sFuncName)
            If GetSystemIntializeInfo(p_oCompDef, sErrDesc) <> RTN_SUCCESS Then Throw New ArgumentException(sErrDesc)


            P_sConString = String.Empty
            P_sConString = "Data Source=" & p_oCompDef.p_sServerName & ";Initial Catalog=" & p_oCompDef.p_sIntDBName & ";User ID=" & p_oCompDef.p_sDBUserName & "; Password=" & p_oCompDef.p_sDBPassword
            AE_EASIPOS_INTEGRATION_DLL.P_sConString = P_sConString

            AE_EASIPOS_INTEGRATION_DLL.P_sSAPConString = "Data Source=" & p_oCompDef.p_sServerName & ";Initial Catalog=" & p_oCompDef.p_sDataBaseName & ";User ID=" & p_oCompDef.p_sDBUserName & "; Password=" & p_oCompDef.p_sDBPassword

            AE_EASIPOS_INTEGRATION_DLL.p_sServerName = p_oCompDef.p_sServerName
            AE_EASIPOS_INTEGRATION_DLL.p_sLicServerName = p_oCompDef.p_sLicServerName
            AE_EASIPOS_INTEGRATION_DLL.p_sDBUserName = p_oCompDef.p_sDBUserName
            AE_EASIPOS_INTEGRATION_DLL.p_sDBPassword = p_oCompDef.p_sDBPassword
            AE_EASIPOS_INTEGRATION_DLL.p_sSQLType = p_oCompDef.p_sSQLType
            AE_EASIPOS_INTEGRATION_DLL.p_sDataBaseName = p_oCompDef.p_sDataBaseName
            AE_EASIPOS_INTEGRATION_DLL.p_sSAPUserName = p_oCompDef.p_sSAPUserName
            AE_EASIPOS_INTEGRATION_DLL.p_sSAPPassword = p_oCompDef.p_sSAPPassword

            'Getting the Data from Invoice Table as DataSet
            Console.WriteLine("Calling ARInvoice_DataSet() ", sFuncName)
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Calling ARInvoice_DataSet()", sFuncName)
            oDataSetInvoice = oARInvoice.ARInvoice_DataSet(P_sConString)

            If Not oDataSetInvoice Is Nothing Then

                'Function to connect the Company
                'If p_oCompany Is Nothing Then
                '    Console.WriteLine("Calling ConnectToTargetCompany() ", sFuncName)
                '    If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Calling ConnectToTargetCompany()", sFuncName)
                'If ConnectToTargetCompany(p_oCompany, sErrDesc) <> RTN_SUCCESS Then Throw New ArgumentException(sErrDesc)
                'End If

                Console.WriteLine("Calling ARInvoice() ", sFuncName)
                If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Calling ARInvoice()", sFuncName)
                If oARInvoice.ARInvoice(oDataSetInvoice, p_oCompany, sErrDesc) <> RTN_SUCCESS Then Throw New ArgumentException(sErrDesc)

            End If
            Console.WriteLine("Completed with SUCCESS ", sFuncName)
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Completed with SUCCESS", sFuncName)

        Catch ex As Exception
            sErrDesc = ex.Message
            Call WriteToLogFile(sErrDesc, sFuncName)
            Console.WriteLine("Completed with ERROR : " & sErrDesc, sFuncName)
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Completed with ERROR", sFuncName)
          
        End Try

    End Sub

End Module
